package com.itheima.service.impl.checkitem;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.checkitem.CheckItemDao;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.pojo.CheckItem;
import com.itheima.service.checkitem.CheckItemService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author 陈功炳
 * @since 2021/11/4 11:27
 */
@Service
public class CheckItemServiceImpl implements CheckItemService {

    @Autowired
    private CheckItemDao checkItemDao;

    @Override
    public Boolean add(CheckItem checkItem) {
        Integer result = checkItemDao.add(checkItem);
        return result > 0;
    }

    @Override
    public PageResult findByCondition(QueryPageBean queryPageBean) {
        Integer pageSize = queryPageBean.getPageSize();
        Integer currentPage = queryPageBean.getCurrentPage();
        String queryString = queryPageBean.getQueryString();
        PageHelper.startPage(currentPage, pageSize);

        Page<CheckItem> page = checkItemDao.findByCondition(queryString);
        long total = page.getTotal();
        List<CheckItem> result = page.getResult();
        return new PageResult(total, result);
    }

    @Override
    public CheckItem findById(Integer id) {
        return checkItemDao.findById(id);
    }

    @Override
    public Boolean edit(CheckItem checkItem) {
        Integer result = checkItemDao.edit(checkItem);
        return result > 0;
    }


    @Override
    public Boolean delete(Integer id) {
        checkItemDao.deleteTCC(id);
        Integer result = checkItemDao.delete(id);
        return result > 0;
    }


}
